import 'package:dio/dio.dart';
import 'package:flutter_learning/isolate/utils/ly_log.dart';

import '../network/base_response.dart';
import 'ly_isolate_balancer.dart';

class LYDataManager extends LYIsolateManager {
  static void test() async {
    final res = await LYIsolateManager.performSelector(requestData, {"deviceId": "123456"});
    LYLog.d("res=====$res");
  }

  static Future<String> requestData(Map parameters) async {
    final deviceId = parameters['deviceId'];
    Dio api = Dio();
    api.options.contentType = 'application/json';
    api.options.connectTimeout = const Duration(seconds: 30);
    api.options.receiveTimeout = const Duration(seconds: 30);
    api.options.headers = {
      "Content-Type": "application/json",
      "product": "reception",
      "device_id": deviceId,
      "ticket": deviceId,
      // "access_token": accessToken,
    };
    // 日志拦截器
    // api.interceptors.add(the_dio.LogInterceptor(responseBody: true));
    final res = await api.post("https://api.ymlinks.com/user/admin/login",
        data: {"username": "test", "password": "666888"});
    final baseResponse = BaseResponse(
      code: BaseResponseCode.success,
      msg: '数据请求成功啦!',
      success: true,
      result: res.data['result'],
    );
    return res.data.toString();
  }
}
